﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bunian.Core.BusinessObjects;
using Bunian.Service;
using Bunian.Core;
using Bunian.Web.Pages;
using Bunian.Web.Common.Code;
using Bunian.Web.Controls;
using Shut;

namespace Bunian.Web.Pages
{
    public partial class _default : UiPage
    {
        private TenderService _srv;

        protected void Page_Load(object sender, EventArgs e)
        {
            _srv = GetPageLifeSpanningObject<TenderService>();

            IList<Orphan> orphans = _srv.GetAllBasedOnType<Orphan>();

            rptChild.DataSource = orphans;
            rptChild.DataBind();

            IList<NeedyFamily> families = _srv.GetAllBasedOnType<NeedyFamily>();

            rptFamilies.DataSource = families;
            rptFamilies.DataBind();
        }

        protected void rptChild_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            switch (e.Item.ItemType)
            {
                case ListItemType.AlternatingItem:
                case ListItemType.Item:

                    Orphan currentOrphan = (Orphan)e.Item.DataItem;

                    CIndividualProfile ucIndividualProfile = (CIndividualProfile)e.Item.FindControl("ucIndividualProfile");
                    ucIndividualProfile.CurrentChild = currentOrphan.ChildInfo;

                    break;
            }
        }

        protected void rptFamilies_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            switch (e.Item.ItemType)
            {
                case ListItemType.AlternatingItem:
                case ListItemType.Item:

                    NeedyFamily currentNeedyFamily = (NeedyFamily)e.Item.DataItem;

                    CFamilyProfile ucFamilyProfile = (CFamilyProfile)e.Item.FindControl("ucFamilyProfile");
                    ucFamilyProfile.CurrentFamily = currentNeedyFamily.FamilyInfo;

                    break;
            }
        }
    }
}